#include "qe_timer.h"



qe_ret qe_timer_set_callback(qe_timer_dev *timer, 
    qe_timer_callback callback, void *args)
{
    qe_ret ret;

    ret = timer->ops->enable_irq(timer, qe_true);
    if (ret != qe_ok) {
        return ret;
    }

    timer->callback = callback;
    timer->callback_args = args;
    return qe_ok;
}

qe_ret qe_timer_start(qe_timer_dev *timer, qe_u32 timeout)
{
    return timer->ops->start(timer, timeout);
}

void qe_timer_stop(qe_timer_dev *timer)
{
    return timer->ops->stop(timer);
}

qe_u32 qe_timer_elapsed(qe_timer_dev *timer)
{
    return timer->ops->elapsed(timer);
}

qe_u64 qe_timer_elapsed_ns(qe_timer_dev *timer)
{
    if (timer->ops->elapsed_ns) {
        return timer->ops->elapsed_ns(timer);
    }
    return 0;
}

qe_ret qe_timer_register(qe_timer_dev *timer, qe_const_str name, qe_timer_ops *ops, void *priv)
{
	qe_dev *dev;

	dev = &(timer->dev);

	dev->type = QE_DEV_TIMER;
	dev->rx_indicate = QE_NULL;
	dev->tx_complete = QE_NULL;

	timer->ops = ops;

	dev->priv = priv;

	return qe_dev_register(dev, name, 0x0);
}